package com.demo.index;

import java.util.List;

import com.demo.common.model.Admin;
import com.demo.common.model.Category;
import com.demo.common.model.Content;
import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;

/**
 * IndexController
 */
public class IndexController extends Controller {
	public void index() {
		
		setAttr("contentPage", Content.dao.paginateAll(getParaToInt(0, 1), 10));
		
		Category category = new Category();
		List<Category> categorylist = category.getCategory();
		this.setAttr("categorylist",categorylist);
		
		Admin admin = new Admin();
		setAttr("user",admin.getUsers()); 
		
		Content contents = new Content();
		List<Content> lists = contents.getC6();
		this.setAttr("lists",lists);
		
		render("index.html");
	}
	
	
	public void content() {
		Category category = new Category();
		List<Category> categorylist = category.getCategory();
		this.setAttr("categorylist",categorylist);
		
		Admin admin = new Admin();
		setAttr("user",admin.getUsers()); 
		
		Content contents = new Content();
		List<Content> lists = contents.getC6();
		this.setAttr("lists",lists);
		
		int id = Integer.parseInt(getPara("id"));
		//System.out.println(id);
		
		Record content = Db.findById("content", id);
		setAttr("content",content); 
		//System.out.println(content);
		render("content.html");
	}
	
	public void searchClass() {
		
		Category category = new Category();
		List<Category> categorylist = category.getCategory();
		this.setAttr("categorylist",categorylist);
		
		Admin admin = new Admin();
		setAttr("user",admin.getUsers()); 
		
		Content contents = new Content();
		List<Content> lists = contents.getC6();
		this.setAttr("lists",lists);
		
		
		String cname = getPara("cname");
		setAttr("cname",cname); 
		setAttr("tablePage", Content.dao.paginate(getParaToInt(0, 1), 10,cname));
		render("searchClass.html");
	}
	
	
	public void search(){
		Category category = new Category();
		List<Category> categorylist = category.getCategory();
		this.setAttr("categorylist",categorylist);
		
		Admin admin = new Admin();
		setAttr("user",admin.getUsers()); 
		
		Content contents = new Content();
		List<Content> lists = contents.getC6();
		this.setAttr("lists",lists);
		
		
		String key = getPara("key");
		setAttr("tablePage", Content.dao.paginateKey(getParaToInt(0, 1), 10,key));
		render("search.html");
	}




}


